package com.cloudm.technician.ui.modules.cloudm_box.change_info

import com.cloudm.technician.data.network.CloudmBoxApi
import com.cloudm.technician.ui.base.RxPresenter

/**
 * 作者: wesley
 * 时间: 2017/12/25
 * 描述: 业务逻辑
 */
class ChangeInfoPresenter(private val view: ChangeInfoContract.View,
                          private val cloudmBoxApi: CloudmBoxApi) : RxPresenter(),
        ChangeInfoContract.Presenter {


    override fun changeCloudBox(deviceId: Int, sn: String) {
        view.showChangeBoxDialog()
        request(cloudmBoxApi.changeCloudmBox(deviceId, sn), view, onSuccess = { info, _ ->
            view.hideChangeBoxDialog()
            when (info) {
                null -> view.showDeviceInfoEmpMsg()
                else -> {
                    info.id = info.deviceId
                    info.createTime = info.gmtCreate
                    view.changeBoxSuccess(info)
                }
            }
        }, onFailure = { errorMsg ->
            view.hideChangeBoxDialog()
            view.changeBoxFailure(errorMsg)
        })
    }


}